<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use app\model\Crew;
use think\db\Query;
use think\Request;

class CrewController extends BaseController
{
	function index()
	{
		$keyword = $this->request->get('keyword');
		$type = $this->request->get('type');#身份:1=导演,2=编剧,3=演员
		$rows = Crew::when(!empty($keyworld),function (Query $query)use($keyword){
			$query->whereLike('name', "%$keyword%");
		})->when(!empty($type),function (Query $query)use($type){
			$query->where('type',$type);
		})->order(['id'=>'desc'])->paginate()->items();
		$this->writeJson($rows);
    }
	
	#添加演员信息
	function create()
	{
		$name = $this->request->post('name');
		$type = $this->request->get('type');
		$image = $this->request->get('image');
		$crew = Crew::create([
			'name'=>$name,
			'type'=>$type,
			'image'=>$image
		]);
		$this->writeJson();
	}
	
}
